package com.quanquan.store.controller.marketActivity;

import com.quanquan.store.dto.marketActivity.MarketActivityDTO;
import com.quanquan.store.entity.marketActivity.MarketActivity;
import com.quanquan.store.request.marketActivity.MarketActivityRequest;
import com.quanquan.store.service.marketActivity.MarketActivityService;
import enums.ResCodeEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.response.ResultBody;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName MarketActivityController
 * @Description
 * @Author Owen
 * @Date 2019/9/17 0017 上午 10:32
 * @Version V1.0
 **/
@RestController
@RequestMapping("/marketActivity")
public class MarketActivityController {

    @Autowired
    private MarketActivityService marketActivityService;

    /**
     * 获取营销活动前置页面信息
     * @param activityRequest
     * @return
     */
    @PostMapping("/getMarketActivityInfo")
    public ResultBody getMarketActivityInfo(@RequestBody MarketActivityRequest activityRequest){

        if(null == activityRequest.getActivityId() || activityRequest.getActivityId() <= 0){
            return new ResultBody(ResCodeEnum.CUSTOM.getCode(), "缺少必要参数");
        }

        MarketActivity marketActivity = marketActivityService.getMarketActivityById(activityRequest.getActivityId());
        if(null == marketActivity){
            return new ResultBody(ResCodeEnum.CUSTOM.getCode(), "活动查询失败");
        }

        MarketActivityDTO marketActivityDTO = new MarketActivityDTO();
        BeanUtils.copyProperties(marketActivity,marketActivityDTO);

        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "success",marketActivityDTO);

    }


    /**
     * 获取所有营销活动列表
     * @return
     */
    @PostMapping("/getMarketActivityList")
    public ResultBody getMarketActivityList(){
        List<MarketActivity> marketActivityList = marketActivityService.getMarketActivityList();
        List<Object> result = new LinkedList<>();
        Map<String,Object> map = null;
        for (MarketActivity marketActivity: marketActivityList) {
            map = new HashMap<>();
            map.put("activityName",marketActivity.getActivityName());
            map.put("activityLogo",marketActivity.getActivityLogo());
            map.put("miniPath",marketActivity.getMiniPath());
            map.put("activityType",marketActivity.getActivityType());
            map.put("linkPath",marketActivity.getLinkPath());
            result.add(map);
        }

        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "success",result);
    }

}
